<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  Architecture
-->
<div ng-controller="ARTEMIS.BrowseQueueController">
  <div class="row-fluid">
    <div class="span6">
      <input class="search-query span12" type="text" ng-model="gridOptions.filterOptions.filterText"
             placeholder="Filter messages">
    </div>
    <div class="span6">
      <div class="pull-right">
        <form class="form-inline">
          <button class="btn" ng-disabled="!gridOptions.selectedItems.length" ng-show="dlq" ng-click="retryMessages()"
                  title="Moves the dead letter queue message back to its original destination so it can be retried" data-placement="bottom">
            <i class="icon-reply"></i> Retry
          </button>
          <button class="btn" ng-disabled="gridOptions.selectedItems.length !== 1" ng-click="resendMessage()"
                    title="Edit the message to resend it" data-placement="bottom">
           <i class="icon-share-alt"></i> Resend
          </button>

          <button class="btn" ng-disabled="!gridOptions.selectedItems.length" ng-click="moveDialog = true"
                  title="Move the selected messages to another destination" data-placement="bottom">
            <i class="icon-share-alt"></i> Move
          </button>
          <button class="btn" ng-disabled="!gridOptions.selectedItems.length"
                  ng-click="deleteDialog = true"
                  title="Delete the selected messages">
            <i class="icon-remove"></i> Delete
          </button>
          <button class="btn" ng-click="refresh()"
                  title="Refreshes the list of messages">
            <i class="icon-refresh"></i>
          </button>
        </form>
      </div>
    </div>
  </div>

  <div class="row-fluid">
    <div class="gridStyle" ng-grid="gridOptions"></div>
  </div>

  <div hawtio-slideout="showMessageDetails" title="{{row.JMSMessageID}}">
    <div class="dialog-body">

      <div class="row-fluid">
        <div class="pull-right">
          <form class="form-horizontal no-bottom-margin">

            <div class="btn-group"
                 hawtio-pager="messages"
                 on-index-change="selectRowIndex"
                 row-index="rowIndex"></div>

            <button class="btn" ng-disabled="!gridOptions.selectedItems.length" ng-click="moveDialog = true"
                    title="Move the selected messages to another destination" data-placement="bottom">
              <i class="icon-share-alt"></i> Move
            </button>

            <button class="btn btn-danger" ng-disabled="!gridOptions.selectedItems.length"
                    ng-click="deleteDialog = true"
                    title="Delete the selected messages">
              <i class="icon-remove"></i> Delete
            </button>

            <button class="btn" ng-click="showMessageDetails = !showMessageDetails" title="Close this dialog">
              <i class="icon-remove"></i> Close
            </button>

          </form>
        </div>
      </div>

      <div class="row-fluid">
        <div class="expandable closed">
          <div title="Headers" class="title">
            <i class="expandable-indicator"></i> Headers & Properties
          </div>
          <div class="expandable-body well">
            <table class="table table-condensed table-striped">
              <thead>
              <tr>
                <th>Header</th>
                <th>Value</th>
              </tr>
              </thead>
              <tbody ng-bind-html-unsafe="row.headerHtml">
              </tbody>
              <!--
                            <tr ng-repeat="(key, value) in row.headers">
                              <td class="property-name">{{key}}</td>
                              <td class="property-value">{{value}}</td>
                            </tr>
              -->
            </table>
          </div>
        </div>
      </div>

      <div class="row-fluid">
        <div>Displaying body as <span ng-bind="row.textMode"></span></div>
        <div hawtio-editor="row.bodyText" read-only="true" mode='mode'></div>
      </div>

    </div>
  </div>

  <div hawtio-confirm-dialog="deleteDialog"
       ok-button-text="Delete"
       on-ok="deleteMessages()">
    <div class="dialog-body">
      <p>You are about to delete
        <ng-pluralize count="gridOptions.selectedItems.length"
                      when="{'1': 'a message!', 'other': '{} messages!'}">
        </ng-pluralize>
      </p>
      <p>This operation cannot be undone so please be careful.</p>
    </div>
  </div>

  <div hawtio-confirm-dialog="moveDialog"
       ok-button-text="Move"
       on-ok="moveMessages()">
    <div class="dialog-body">
      <p>Move
        <ng-pluralize count="gridOptions.selectedItems.length"
                      when="{'1': 'message', 'other': '{} messages'}"></ng-pluralize>
        to: <input type="text" ng-model="queueName" placeholder="Queue name"
                   typeahead="title.unescapeHTML() for title in queueNames($viewValue) | filter:$viewValue" typeahead-editable='true'></p>
      <p>
        You cannot undo this operation.<br>
        Though after the move you can always move the
        <ng-pluralize count="gridOptions.selectedItems.length"
                      when="{'1': 'message', 'other': 'messages'}"></ng-pluralize>
        back again.
      </p>
    </div>
  </div>

</div>

